<?php
class Qp_Debug
{	
	private static $_dbProfiler;
	private static $_times;
	
	public static function infos()
	{
		$query_count = 0;
		$time = 0;
		echo '<table class="debugTable">';
		foreach ( self::$_dbProfiler as $event ) {
                    $query_count++;
		    echo "<tr>";
		    $time += $event->getElapsedSecs() ;
		    echo "<td>" . $event->getName() . "</td><td>" . sprintf ( "%f" , $event->getElapsedSecs() ) . "</td>";
		    echo "<td>" . $event->getQuery() . "</td>" ;
		    $params = $event->getParams();
                    echo "<td>";
                    echo join(', ', $params);
                    echo "</td>";
		    echo "</tr>";
		}
		echo "</table>";
		echo "Total time: " . $time . ", query count: $query_count <br>\n ";
	}
	public static function log($infos='')
	{
		if(!Qp_Setup::DEBUG)
			return;	
		self::$_times[microtime()] = $infos;
	}
	public static function addConnectionListener()
	{
		if(!Qp_Setup::DEBUG)
			return; 
			
		self::$_dbProfiler = new Doctrine_Connection_Profiler();
		Doctrine_Manager::connection()->setListener(self::$_dbProfiler);

	}
}